package com.community.process._1010.dao.view;

import com.community.process._1010.common.utils.tree.TreeNode;
import com.community.process._1010.dao.entity.ProcessCategory;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.List;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "分类展示DTO")
public class ProcessCategoryNodeView implements TreeNode<Long, ProcessCategoryNodeView>, Serializable {

    private static final long serialVersionUID = 7022953566101647359L;

    @Schema(description = "ID")
    private Long id;

    @Schema(description = "名称")
    private String name;

    @Schema(description = "类目级别")
    private Integer level;

    @Schema(description = "上级菜单ID")
    private Long parentId;

    @Schema(description = "编码")
    private String treeCode;

    @Schema(description = "图标")
    private String icon;

    @Schema(description = "排序")
    private Integer sort;

    @Schema(description = "分类类型 1 食材 2 菜品")
    private Integer type;

    @Schema(description = "子节点")
    private List<ProcessCategoryNodeView> children;

    public ProcessCategoryNodeView(ProcessCategory category) {
        this.id = category.getId();
        this.name = category.getName();
        this.level = category.getLevel();
        this.parentId = category.getParentId();
        this.treeCode = category.getTreeCode();
        this.icon = category.getIcon();
        this.sort = category.getSort();
        this.type = category.getType();
    }

    @Override
    public Long id() {
        return this.id;
    }

    @Override
    public Long parentId() {
        return this.parentId;
    }

    @Override
    public boolean root() {
        return this.parentId == null;
    }

    @Override
    public void setChildren(List<ProcessCategoryNodeView> children) {
        this.children = children;
    }

    @Override
    public List<ProcessCategoryNodeView> getChildren() {
        return this.children;
    }
}
